import java.util.Scanner;


public class UniqueDuplicate 
{

	public static void main(String[] args) 
	{
		Scanner s = new Scanner(System.in);
		System.out.println("Enter the size of the list to be sorted:Default is 5");
		
		int size =5;
		
		try
		{
			size = s.nextInt();
		}
		catch(Exception e)
		{
			size =5;
			s= new Scanner(System.in);
			System.out.println("Default size is set as 5:"+e+"\n");
		}
		
		System.out.println("Enter the number to be sorted:");
					
		int array[] = new int[size];
		int i=0;
		
		while(i<size)
		{
			try
			{
				array[i] = s.nextInt();
				i++;					
			}
			catch(Exception e)
			{
				System.out.println("Invalid value entered:"+e);
				s = new Scanner(System.in);
			}
		}
		
//identifying unique and duplicates
		boolean duplicate;
		int z=0,x=0;
		int dup[]=new int[size];
		int count[] = new int [size];
		int unique[] = new int[size];
		
		// for loop to form the duplicate list
		for (i=0;i<size;i++)
		{
			duplicate = false;
			
			for(int j=i+1;j<=size-1;j++)
			{
				if (array[i] == array[j])
				{
					duplicate = true;				
				}
				
			}//end of inner for lop
			if (duplicate)
			{
				boolean found = false;
				for (int temp=0;temp<z;temp++)
				{ 
					if (dup[temp] == array[i])
					{
						count[temp]++;
						found = true;
					}
				}
				if (found == false) 
				{
					dup[z++]=array[i];
					count[z-1]=2;
				}
			}
		}//end of outer for loop
		
		// fpr loop to form the unique list
		for (i=0;i<size;i++)
		{
			duplicate = false;
			
			for(int j=0;j<z;j++)
			{
				if (array[i] == dup[j])
				{
					duplicate = true;				
				}
				
			}//end of inner for lop
			if (!duplicate)
				unique[x++]=array[i];
		}//end of outer for loop
		
		System.out.println("\nDuplicate list:\n");
		
		for(i=0;i<z;i++)
		{
			System.out.println(dup[i] +" "+ count[i]);
		}
		System.out.println("\nUnique list:\n");
		
		for(i=0;i<x;i++)
		{
			System.out.println(unique[i]);
		}
	}

}
